<?php

namespace App\Library\Junda\src;

use App\Library\Junda\JunDaApiClient;

class CardService
{

    /**
     * 查询指定IC卡的信息
     * @param $cardno
     * @return mixed
     */
    public static function GetICBalance($cardno)
    {
        $url = 'https://apiv2.ljda.net/api/GetICBalance';
        $params['cardno']=$cardno;
        $response = JunDaApiClient::sendRequest($url,'GET',$params);
        return $response;

    }

    /**
     *  更新指定IC卡的信息
     * @param $cardno
     * @param $name
     * @param $tel
     * @return mixed
     */
    public static function UpdateICBalance($cardno,$name,$tel)
    {
        $url = 'https://apiv2.ljda.net/api/UpdateICBalance';
        $response = JunDaApiClient::sendRequest($url,'GET',['cardno'=>$cardno,'name'=>$name,'tel'=>$tel]);
        return $response;
    }
    /**已知卡号第三方充值
     * cardno    是    IC卡号
     * cardmoney    是    充值金额【单位分】
     * buymoney    是    实收金额【单位分】
     * @return void
     */
    public static function ICAccountCharge($cardno='',$cardmoney='',$buymoney='')
    {
        $url = 'https://apiv2.ljda.net/api/ICAccountCharge';
        if (empty($cardno)){
            return ['code'=>0,'msg'=>'充值卡号不能为空'];
        }
        if (empty($cardmoney)){
            return ['code'=>0,'msg'=>'充值金额不能为空'];
        }

        if (empty($buymoney)){
            return ['code'=>0,'msg'=>'实付金额不能为空'];
        }

        $params['cardno']=$cardno;
        $params['cardmoney']=$cardmoney*100;
        $params['buymoney']=$buymoney*100;
        $response = JunDaApiClient::sendRequest($url,'GET',$params);
        if (!$response['success']){
            return ['code'=>0,'msg'=>"充值失败"];
        }
        return ['code'=>1,'msg'=>'充值成功'];
    }
    // 查询当前商户IC卡列表
    public static function GetCardList($params=[])
    {
        $url = 'https://apiv2.ljda.net/api/GetCardList';
        $response = JunDaApiClient::sendRequest($url,'POST',json_encode($params));
        return $response;
    }

    /**
     *  解绑指定IC卡的用户信息
     * @param $cardno
     * @param $tel
     * @return mixed
     */
    public function UnbindlingIC($cardno,$tel)
    {
        $url = 'https://apiv2.ljda.net/api/UnbindlingIC?cardno=no&tel=telephone';
        $response = JunDaApiClient::sendRequest($url,'GET',['cardno'=>$cardno,'tel'=>$tel]);
        return $response;
    }
    /**
     * @param $params
     * @return void
     * @throws
     * @throws
     */
    // 查询卡片列表Sec 4.2
    public static function GetCardListSec($params=[])
    {
        $url = 'https://apiv2.ljda.net/api/GetCardListSec';
        $response = JunDaApiClient::sendRequest($url,'POST',json_encode($params));
        return $response;
    }
    // 查询当前商户IC卡列表
    public function GetCardBalanceList()
    {
        $url = 'https://apiv2.ljda.net/api/GetCardBalanceList';
    }
    // 查询指定IC的充值记录

    /**
     * cardno    是    指定的IC卡的卡号
     * start_no    否    开始拉取的序号，不填默认从头开始拉取
     * count    否    本次获取数量,默认是最大值1000.
     * is_asc    否    是否日期升序排列,默认false.
     * @return void
     */
    public function GetCardCharge($cardno)
    {
        $url = 'https://apiv2.ljda.net/api/GetCardCharge';

        $params['cardno']=$cardno;
        $response = JunDaApiClient::sendRequest($url,'POST',json_encode($params));

        return $response;

    }

    /**
     * 电子卡号生成
     * @param $eqid
     * @return mixed
     */
    public static function AddCardGenRecord($eqid)
    {
        $url = 'https://apiv2.ljda.net/api/AddCardGenRecord';
        $params['eqid']=$eqid;
        $response = JunDaApiClient::sendRequest($url,'POST',json_encode($params));
        return $response;
    }

}
